/-app ...
/-app/files ...
FileEntry.ts
FileList.ts
FolderEntry.ts
functions.ts
/-app/layout
Application.css
Application.html
TestCase.html
TestPage.css
TestPage.html
Welcome.html
/-app/tests
Application.ts
functions.ts
/-boot
/-docs
/-docs/api
DocumentEditor.ts
DocumentHandler.ts
DocumentStorageServices.ts
/-feartures
/-feartures/api
/-fearures
/-fearures/api
/-features
/-features/api
DocumentHost.ts
Host.ts
Tool.ts
/-imports
/-koBindings
/-storage
/-tests
/-typings
base.css
readme.md
stringUtils.ts
teapo.html
try.html
try.js
1
module teapo.app.files { 
2
 
3
  /**
4
   * Convert string path into an array of path parts,
5
   * processing '..' as necessary.
6
   */
7
  export function normalizePath(path: string): string[] {
8
    if (!path) return [];
9
 
10
    var pathMid = stripOuterSlashes(path);
11
    var split = pathMid.split('/');
12
 
13
    var result: string[] = [];
14
    for (var i = 0; i < split.length; i++) {
15
      if (split[i] === '..') {
16
        if (result.length)
17
          result.length--;
18
        continue;
19
      }
20
      else if (split[i] === '.' || split[i] === '') {
21
        continue;
22
      }
23
      else {
24
        result.push(split[i]);
25
      }
26
    }
27
    return result;
28
  }
29
 
30
  function stripOuterSlashes(path: string) {
31
    var start = 0;
32
    while (path.charAt(start) === '/')
33
      start++;
34
 
35
    var end = Math.max(start, path.length - 1);
36
    while (end > start && path.charAt(end) === '/')
37
      end--;
38
 
39
    var pathMid = start === 0 && end === path.length - 1 ? path : path.slice(start, end + 1);
40
    return pathMid;
41
  }
42
  
43
}